﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace School
{
    public class Student
    {
        private static readonly int MIN_ID = 10000;
        private static readonly int MAX_ID = 99999;

        private string name = string.Empty;
        private int id = default(int);

        public string Name
        {
            get { return this.name; }
        }

        public int Id
        {
            get { return this.id; }
        }

        public Student(string name, int id)
        {
            if (name == null)
            {
                throw new NullReferenceException("Name connot be null");
            }
            if (id < MIN_ID || id > MAX_ID)
            {
                throw new ArgumentException(String.Format("The student Id must be in range from {0} to {1}", MIN_ID, MAX_ID));
            }

            this.name = name;
            this.id = id;

            if (School.Add(this) == false)
            {
                throw new DuplicateWaitObjectException(String.Format("Student with id: {0} already exists", id));
            }
        }

        public override int GetHashCode()
        {
            return this.id.GetHashCode();
        }
    }
}
